package cn.kongwg.demo05;

import java.io.*;
import java.util.Random;

/**
 * @author kongwg
 * @create 2021-06-07 15:56
 */
public class Maxint implements Serializable {


    private static final long serialVersionUID = -8084340783367209806L;

    public void Maxint() {

    }


    public static void main(String[] args) throws IOException, ClassNotFoundException {
        Car car = new Car(1,"22");
        Car clone = clone(car);
        clone.setId(222);
        System.out.println(car);

        System.out.println(clone);


//        short i = 1;
//        i = (short) (i +1);



//        outer:
//        for (int i = 0; i < 3; i++)
//            inner:for (int j = 0; j < 2; j++) {
//                if (j == 1)
//                    continue outer;
//                System.out.println(j + " and " + i);
//            }

//        int value = getValue(2);
//        System.out.println("value = " + value);
        double random = Math.round(-11.2);
        System.out.println("random = " + random);
    }

    public static <T extends Serializable> T clone(T obj) throws IOException, ClassNotFoundException {
        ByteArrayOutputStream bout = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(bout);
        oos.writeObject(obj);

        ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
        ObjectInputStream ois = new ObjectInputStream(bin);

        return (T) ois.readObject();
    }

    public static int getValue(int i) {
        int result = 0;
        switch (i) {
            case 1:
                result = result + i;
            case 2:
                result = result + i * 2;
            case 3:
                result = result + i * 3;
        }
        return result;
    }
}
